package com.qidian.mes.md.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.md.mapper.MdUnitMeasureMapper;
import com.qidian.mes.md.service.MdUnitMeasureService;
import com.qidian.mes.pojo.MdItem;
import com.qidian.mes.pojo.MdUnitMeasure;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;
import java.util.Objects;

/**
 * @Author 32郗建狄
 * @Company GX631
 * Time 2023/10/28 9:48
 * Description
 */
@Service
public class MdUnitMeasureServiceImpl implements MdUnitMeasureService {
    @Autowired
    private MdUnitMeasureMapper mdUnitMeasureMapper;
    @Override
    public MESResult list(int page, int limit, MdUnitMeasure mdUnitMeasure) {

        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page,limit);
        List<MdUnitMeasure> list = mdUnitMeasureMapper.list(mdUnitMeasure);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<MdUnitMeasure> pageInfo = new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult save(MdUnitMeasure mdUnitMeasure) {
        if (Objects.nonNull(mdUnitMeasure)){
            return MESResult.ok(mdUnitMeasureMapper.save(mdUnitMeasure));
        }
        return MESResult.empty();
    }

    @Override
    public MESResult delete(Long id) {
        if (Objects.nonNull(id)){
            return MESResult.updateIsOk(mdUnitMeasureMapper.delete(id));
        }
        return MESResult.empty();
    }

    @Override
    public MESResult deletes(Long[] measureId) {
        if (Objects.nonNull(measureId)){
            return MESResult.ok(mdUnitMeasureMapper.deletes(measureId)+"");
        }
        return MESResult.empty();
    }

    @Override
    public MESResult getAllMeasure() {
        return MESResult.ok(mdUnitMeasureMapper.getAllMeasure());
    }

    @Override
    public MESResult get(Long id) {

        if (Objects.nonNull(id)){
            return MESResult.ok(mdUnitMeasureMapper.get(id));
        }
        return MESResult.empty();
    }

    @Override
    public MESResult update(MdUnitMeasure mdUnitMeasure) {
        if (Objects.nonNull(mdUnitMeasure)){
            return MESResult.ok(mdUnitMeasureMapper.update(mdUnitMeasure));
        }
        return MESResult.empty();
    }
}
